package com.ms.oschina.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;

import com.ms.oschina.api.remote.OsChinaApi;
import com.ms.oschina.base.BaseViewHolder;
import com.ms.oschina.bean.Active;
import com.ms.oschina.bean.ActiveList;
import com.ms.oschina.bean.Constants;
import com.ms.oschina.bean.Tweet;
import com.ms.oschina.fragment.MessageFragment;
import com.ms.oschina.ui.activity.TweetsDetailsActivity;
import com.ms.oschina.util.UiUtils;
import com.ms.oschina.viewholder.AboutMeViewHolder;

/**
 * At 和评论
 * 
 * @author Administrator
 * 
 */
public class AboutMeAdapter extends PageIndexListAdapter<Active> {

	public AboutMeAdapter(AbsListView listView, List<Active> list,
			boolean loadMore) {
		super(listView, list, loadMore);
	}

	@Override
	public void onNormalItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		Active tweet = getListData().get(position);
		Context context = UiUtils.getContext();
		Intent intent = new Intent(context, TweetsDetailsActivity.class);
		intent.putExtra(Constants.TWEETSDETAILSID, tweet.getObjectId());
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

	@Override
	public BaseViewHolder<Active> getItemViewHolder() {
		AboutMeViewHolder viewHolder = new AboutMeViewHolder();
		return viewHolder;
	}

	@Override
	public void getHolder(BaseViewHolder<Active> holder) {
		AboutMeViewHolder viewHolder = (AboutMeViewHolder) holder;
		int mark = getMark();
		viewHolder.setMark(mark);
	}

	@Override
	public List<Active> getLoadMoreData() throws Exception {
		int mark = getMark();
		switch (mark) {
		case MessageFragment.ATME:
			return OsChinaApi
					.getAboutMeInfo(pageIndex, ActiveList.CATALOG_ATME);
		case MessageFragment.COMMENT:
			return OsChinaApi.getAboutMeInfo(pageIndex,
					ActiveList.CATALOG_COMMENT);
		}
		return null;
	}
}
